﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class webadmin_pages_ajax_tinnhan_page : System.Web.UI.Page
{
    public string act = "";
    public Common comm = new Common();
    public string del = "";
    private DataTable dtt;
    public string id = "";
    public string mess = "";
    public string messok = "";
    private string sFrom = "";
    private string sql = "";
    private string sSelect = "";
    private string sWhere = "";
    public string type = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        if (this.Session["UserID"] == null)
        {
            this.mess = "Bạn đ\x00e3 hết thời hạn của quyền đăng nhập n\x00e0y, h\x00e3y tho\x00e1t v\x00e0 đăng nhập lại để tiếp tục thao t\x00e1c!";
        }
        else
        {
            this.sql = "";
            this.sSelect = "";
            this.sFrom = "";
            this.sWhere = "";
            if (!string.IsNullOrEmpty(base.Request.Params["actsms"]))
            {
                this.act = base.Request.Params["actsms"];
            }
            if (!string.IsNullOrEmpty(base.Request.Params["typesms"]))
            {
                this.type = base.Request.Params["typesms"];
            }
            if (!string.IsNullOrEmpty(base.Request.Params["idsms"]))
            {
                this.id = base.Request.Params["idsms"];
            }
            if (!string.IsNullOrEmpty(base.Request.Params["del"]))
            {
                this.del = base.Request.Params["del"];
            }
            this.sSelect = "select * from HeThong_tin_nhan";
            if (this.type == "0")
            {
                this.sWhere = " nguoi_nhan=dbo.DoanhNghiep_doanh_nghiep.ma_doanh_nghiep AND  nguoi_gui=dbo.ConNguoi_nguoi.ma_nguoi and kieu_nguoi_gui=0";
                this.sFrom = " dbo.HeThong_tin_nhan,dbo.ConNguoi_nguoi,dbo.DoanhNghiep_doanh_nghiep";
                this.sSelect = "HeThong_tin_nhan.*,dbo.ConNguoi_nguoi.ho_ten AS ten_nguoi_gui ,dbo.DoanhNghiep_doanh_nghiep.ten_doanh_nghiep AS ten_nguoi_nhan";
            }
            else if (this.type == "1")
            {
                this.sWhere = " nguoi_gui=dbo.DoanhNghiep_doanh_nghiep.ma_doanh_nghiep AND  nguoi_nhan=dbo.ConNguoi_nguoi.ma_nguoi and kieu_nguoi_gui=1";
                this.sFrom = " dbo.HeThong_tin_nhan,dbo.ConNguoi_nguoi,dbo.DoanhNghiep_doanh_nghiep";
                this.sSelect = "HeThong_tin_nhan.*,dbo.ConNguoi_nguoi.ho_ten AS ten_nguoi_nhan ,dbo.DoanhNghiep_doanh_nghiep.ten_doanh_nghiep AS ten_nguoi_gui";
            }
            else if (this.type == "2")
            {
                this.sWhere = " nguoi_gui=0 AND  nguoi_nhan=dbo.DoanhNghiep_doanh_nghiep.ma_doanh_nghiep and kieu_nguoi_gui=2";
                this.sFrom = " dbo.HeThong_tin_nhan,dbo.DoanhNghiep_doanh_nghiep";
                this.sSelect = "HeThong_tin_nhan.*,ten_nguoi_gui='Trung t\x00e2m GTVL' ,dbo.DoanhNghiep_doanh_nghiep.ten_doanh_nghiep AS ten_nguoi_nhan";
            }
            else if (this.type == "3")
            {
                this.sWhere = " nguoi_gui=0 AND  nguoi_nhan=dbo.ConNguoi_nguoi.ma_nguoi and kieu_nguoi_gui=3";
                this.sFrom = " dbo.HeThong_tin_nhan,dbo.ConNguoi_nguoi";
                this.sSelect = "HeThong_tin_nhan.*,ten_nguoi_gui='Trung t\x00e2m GTVL' ,dbo.ConNguoi_nguoi.ho_ten AS ten_nguoi_nhan";
            }
            if (this.act == "0")
            {
                this.sWhere = this.sWhere + " and da_doc=0";
            }
            else if (this.act == "1")
            {
                this.sWhere = this.sWhere + " and da_doc=1";
            }
            else if (this.act == "2")
            {
                this.sWhere = this.sWhere + " and da_doc IS NOT NULL";
            }
            if (this.del == "del")
            {
                this.sql = "delete from HeThong_tin_nhan where id='" + this.id + "'";
                this.comm.execNoneQuery(this.sql);
            }
            else if (this.del == "upd")
            {
                this.sql = "Update HeThong_tin_nhan set da_doc=1 where id='" + this.id + "'";
                this.comm.execNoneQuery(this.sql);
            }
            this.sql = "Select " + this.sSelect + " from " + this.sFrom + " where " + this.sWhere + " order by ngay_gui desc";
            this.dtt = this.comm.getDataTable(this.sql);
            this.rpt_list_obj.DataSource = this.dtt;
            this.rpt_list_obj.DataBind();
        }
    }

    protected void rpt_list_obj_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
    }
}
